﻿using System;
using System.Linq.Expressions;
using Domain.Core.Specification;
using Domain.MainModule.Entities;

namespace Domain.MainModule.Phones
{
    public class PhoneTypeNameSpecification : Specification<PhoneType>
    {
       #region public properties

        public string PhoneTypeName
        {
            get;
            set;
        }

        #endregion

        #region constructor

        public PhoneTypeNameSpecification(string phoneTypeName)
        {
            this.PhoneTypeName = phoneTypeName;
        }

        #endregion

        #region public methods

        public override Expression<Func<PhoneType, bool>> SatisfiedBy()
        {
            Specification<PhoneType> spec = new TrueSpecification<PhoneType>();
            if (!string.IsNullOrEmpty(this.PhoneTypeName) && !string.IsNullOrWhiteSpace(this.PhoneTypeName))
            {
                spec &= new DirectSpecification<PhoneType>(c => c.Name.ToLower() == this.PhoneTypeName.ToLower());
            }

            return spec.SatisfiedBy();
        }

        #endregion
    }
}
